<template>
	<view class="resume flex-d-c">
		<!-- 制作简历的页面布局 start -->
		<view class="header">
			<uni-steps :options="stepList" :active="stepNum"></uni-steps>
		</view>
		
		<view class="flex-over">
			<template v-if="stepNum === 0">
				<introduce-my-self ></introduce-my-self>
			</template>
			<template v-else-if="stepNum === 1">
				<skill-component ref="skillComponent"></skill-component>
			</template>
			<template v-else>
				<project-component ref="projectComponent"></project-component>
			</template>
		</view>
		
		<footer-component :stepNum = "stepNum" @nextBtn=" nextBtn "></footer-component>
		<!-- 制作简历的页面布局 end -->
	</view>
</template>

<script>
	import  introduceMySelf  from '../../component/introduceMySelf.vue'
	import  skillComponent  from '../../component/skillComponent.vue'
	import projectComponent from '../../component/projectComponent.vue'
	import footerComponent from '../../component/footer.vue'
	export default{
		name:'resume',
		components:{
			introduceMySelf	,skillComponent,projectComponent,footerComponent
		},
		data(){
			return{
				stepList:[{title: '自我介绍'}, {title: '技能'}, {title: '项目'}],
				stepNum: 0,
				type: ''
			}
		},
		methods:{
			//获取简历数据
			getResume(){
				const params = {
					openid: uni.getStorageSync('openid') || '',
					type: 8
				}
				this.$api('writeProject',params).then(res=>{
					console.log('获取简历模板的数据',res)
					if(res.result.status === 'S'){
						this.$store.commit('setResume',res.result.data.data[0].data)
					}
				}).catch(msg=>{
					console.log('获取简历模板数据报错=======',msg)
					
				})
			},
			nextBtn(k){
				console.log(k)
				if(k == 0){
					this.stepNum = this.stepNum <= 0 ? 0 : this.stepNum -=1;
					if(this.stepNum == 1) {
						uni.setStorageSync('threeList',this.$store.state.threeList)
					}
					if(this.stepNum == 0){
						uni.setStorageSync('twoKeyList',this.$store.state.twoKeyList)
						uni.setStorageSync('twoSkillList',this.$store.state.twoSkillList)
					}
				}else{
					this.stepNum+=1
					switch (this.stepNum){
						case 1:
							uni.setStorageSync('oneList',this.$store.state.oneList)
							break;
						case 2:
							uni.setStorageSync('twoKeyList',this.$store.state.twoKeyList)
							uni.setStorageSync('twoSkillList',this.$store.state.twoSkillList)
							break;
						case 3:
							uni.setStorageSync('threeList',this.$store.state.threeList)
							if(this.type !=='edit'){
								this.addResume();
							}else{
								this.setResume();
							}
							
							break;
						default:
							break;
					}
					this.stepNum = this.stepNum >= 2 ? 2 :  this.stepNum ;
					// console.log(this.$store.state.oneList)
					
				}
			},
			setResume(){
				//修改简历
				const params = {
					type:6,
					openid:uni.getStorageSync('openid'),
					oneList : this.$store.state.oneList,
					twoKeyList: this.$store.state.twoKeyList,
					twoSkillList: this.$store.state.twoSkillList,
					threeList: this.$store.state.threeList
				}
				this.$api('writeProject',params).then(res=>{
					console.log(res);
					if(res.result.status==='S'){
						uni.showToast({
							title: '简历修改成功',
							icon:'none',
							mask:true
						})
						setTimeout(()=>{
							uni.reLaunch({
								url:'/pages/index/index'
							})
						},2000)
					}
				}).catch(msg=>{
					console.log(msg);
					uni.showToast({
						title: msg.message,
						icon: 'none'
					})
				})
			},
			//添加简历,数据
			addResume(){
				//用户点击提交
				const params = {
					type:1,
					openid:uni.getStorageSync('openid'),
					oneList : this.$store.state.oneList,
					twoKeyList: this.$store.state.twoKeyList,
					twoSkillList: this.$store.state.twoSkillList,
					threeList: this.$store.state.threeList
				}
				this.$api('writeProject',params).then(res=>{
					console.log(res);
					if(res.result.status==='S'){
						uni.showToast({
							title: '简历制作中',
							icon:'loading',
							mask:true
						})
						setTimeout(()=>{
							uni.reLaunch({
								url:'/pages/index/index'
							})
						},2000)
					}
				}).catch(msg=>{
					console.log(msg);
					uni.showToast({
						title: msg.message,
						icon: 'none'
					})
				})
			}
		},
		onLoad(options) {
			if(options?.type == 'edit'){//修改简历
				this.type = options.type
				this.getResume()
			}
		},
		
		
	}
</script>

<style lang="scss">
	page{
		height: 100%;
	}
	.resume{
		width: 100%;
		height: 100%;
		box-sizing: border-box;
		padding-bottom: env(safe-area-inset-bottom);
		font-size: 28upx;
		font-size: 28upx;
		.header{
			margin: 20upx 0;
		}
		
		
	}
	
</style>
